package com.itwxz.system.controller.pc;

import com.itwxz.common.annotation.Log;
import com.itwxz.common.core.controller.BaseController;
import com.itwxz.common.core.domain.AjaxResult;
import com.itwxz.common.core.page.TableDataInfo;
import com.itwxz.common.enums.BusinessType;
import com.itwxz.common.utils.poi.ExcelUtil;
import com.itwxz.system.domain.po.WxzConfig;
import com.itwxz.system.service.IWxzConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 手机端参数配置Controller
 *
 * @author gastronome
 * @date 2025-04-09
 */
@Tag(name = "手机端参数配置Controller")
@RestController
@RequestMapping("/wxz/config")
public class WxzConfigController extends BaseController {
    @Autowired
    private IWxzConfigService wxzConfigService;

    /**
     * 查询手机端参数配置列表
     */
    @Operation(summary = "查询手机端参数配置列表")
    @PreAuthorize("@ss.hasPermi('wxz:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxzConfig wxzConfig) {
        startPage();
        List<WxzConfig> list = wxzConfigService.selectWxzConfigList(wxzConfig);
        return getDataTable(list);
    }

    /**
     * 导出手机端参数配置列表
     */
    @Operation(summary = "导出手机端参数配置列表")
    @PreAuthorize("@ss.hasPermi('wxz:config:export')")
    @Log(title = "手机端参数配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxzConfig wxzConfig) {
        List<WxzConfig> list = wxzConfigService.selectWxzConfigList(wxzConfig);
        ExcelUtil<WxzConfig> util = new ExcelUtil<WxzConfig>(WxzConfig.class);
        util.exportExcel(response, list, "手机端参数配置数据");
    }

    /**
     * 获取手机端参数配置详细信息
     */
    @Operation(summary = "获取手机端参数配置详细信息")
    @PreAuthorize("@ss.hasPermi('wxz:config:query')")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId) {
        return success(wxzConfigService.getById(configId));
    }

    /**
     * 新增手机端参数配置
     */
    @CacheEvict(value = "config", key = "'repair'")
    @Operation(summary = "新增手机端参数配置")
    @PreAuthorize("@ss.hasPermi('wxz:config:add')")
    @Log(title = "手机端参数配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxzConfig wxzConfig) {
        return toAjax(wxzConfigService.save(wxzConfig));
    }

    /**
     * 修改手机端参数配置
     */
    @CacheEvict(value = "config", key = "'repair'")
    @Operation(summary = "修改手机端参数配置")
    @PreAuthorize("@ss.hasPermi('wxz:config:edit')")
    @Log(title = "手机端参数配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxzConfig wxzConfig) {
        return toAjax(wxzConfigService.updateById(wxzConfig));
    }

    /**
     * 删除手机端参数配置
     */
    @CacheEvict(value = "config", key = "'repair'")
    @Operation(summary = "删除手机端参数配置")
    @PreAuthorize("@ss.hasPermi('wxz:config:remove')")
    @Log(title = "手机端参数配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds) {
        return toAjax(wxzConfigService.removeByIds(Arrays.asList(configIds)));
    }
}
